CaptureVideoPreviewView

<CaptureVideoPreviewView/> is the SwiftUI surface for rendering a live preview of any AVCaptureSession you have built. It mirrors <VideoRecorderPreviewView/> but accepts an arbitrary session, so it works with the pipelines you assemble manually.

<CaptureVideoPreviewView
  session={session}
  videoDevice={camera}
  videoGravity="resizeAspectFill"
  cornerRadius={12}
  masksToBounds
/>

Props

PropTypeDefaultDescription
sessionAVCaptureSessionrequiredThe session to render. Must already have a video input attached to actually show frames.
videoDeviceAVCaptureDeviceoptionalPass the device backing the input. Doing so enables AVCaptureDevice.RotationCoordinator, so the preview rotates with the device. Without it the preview keeps the connection's default orientation.
videoGravity'resize' | 'resizeAspect' | 'resizeAspectFill''resizeAspectFill'Same semantics as AVLayerVideoGravity.
isVideoMirroredbooleansystem defaultForce the connection's videoMirrored flag (e.g. mirror front camera).
cornerRadiusnumber0Convenience for rounded preview tiles. Set masksToBounds if you need clipping.
masksToBoundsbooleanfalseApply masksToBounds to the preview layer (turn on for cornerRadius).

Lifecycle

The preview view does not start or stop the session for you — call session.startRunning() from JavaScript when you want frames flowing. A typical SwiftUI-style pattern:

function CameraPage() {
  const session = useMemo(() => buildSession(), [])

  useEffect(() => {
    session.startRunning()
    return () => {
      session.stopRunning()
      session.dispose()
    }
  }, [])

  return (
    <VStack>
      <CaptureVideoPreviewView session={session} videoDevice={camera} />
      <Button title="Capture" action={() => photoOutput.capturePhoto()} />
    </VStack>
  )
}

Notes

  • The same AVCaptureSession may only be rendered by one preview view at a time.
  • Changing videoGravity / isVideoMirrored / cornerRadius after the view has rendered re-applies them on the next layout pass.
  • For multi-cam setups (multiple inputs in the same session) use a single preview view; AVFoundation does the compositing internally.